package com.fc.test.service;

import java.util.List;

import com.fc.test.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.TAbbBannerMapper;
import com.fc.test.model.auto.TAbbBanner;
import com.fc.test.model.auto.TAbbBannerExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 * Service
* @Title: TAbbBannerService.java 
* @Package com.fc.test.entity 
* @author fuce
* @email 87766867@qq.com
* @date 2019-08-06 18:00:08  
 */
@Service
public class TAbbBannerService implements BaseService<TAbbBanner, TAbbBannerExample>{
	@Autowired
	private TAbbBannerMapper tAbbBannerMapper;
	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<TAbbBanner> list(Tablepar tablepar,String name){
	        TAbbBannerExample testExample=new TAbbBannerExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andSkipUrlLike(name);
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<TAbbBanner> list= tAbbBannerMapper.selectByExample(testExample);
	        PageInfo<TAbbBanner> pageInfo = new PageInfo<TAbbBanner>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
		List<String> lista=Convert.toListStrArray(ids);
		TAbbBannerExample example=new TAbbBannerExample();
		example.createCriteria().andIdIn(lista);
		return tAbbBannerMapper.deleteByExample(example);
	}
	
	
	@Override
	public TAbbBanner selectByPrimaryKey(String id) {
		
		return tAbbBannerMapper.selectByPrimaryKey(id);
	}

	
	@Override
	public int updateByPrimaryKeySelective(TAbbBanner record) {
		return tAbbBannerMapper.updateByPrimaryKeySelective(record);
	}
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(TAbbBanner record) {
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		record.setCreatTime(DateUtil.getCurrentDateTimeStr());
		return tAbbBannerMapper.insertSelective(record);
	}


	@Override
	public int updateByExampleSelective(TAbbBanner record, TAbbBannerExample example) {
		
		return tAbbBannerMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(TAbbBanner record, TAbbBannerExample example) {
		
		return tAbbBannerMapper.updateByExample(record, example);
	}

	@Override
	public List<TAbbBanner> selectByExample(TAbbBannerExample example) {
		
		return tAbbBannerMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(TAbbBannerExample example) {
		
		return tAbbBannerMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(TAbbBannerExample example) {
		
		return tAbbBannerMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param TAbbBanner
	 * @return
	 */
	public int checkNameUnique(TAbbBanner tAbbBanner){
		TAbbBannerExample example=new TAbbBannerExample();
		example.createCriteria().andSkipUrlEqualTo(tAbbBanner.getSkipUrl());
		List<TAbbBanner> list=tAbbBannerMapper.selectByExample(example);
		return list.size();
	}

	//------------------------------------------------------------------接口---------------------------------------------------------------
	public List<TAbbBanner> getIndexBanner(){
		List<TAbbBanner> list = tAbbBannerMapper.getIndexBanner(1);
		return list;
	}

	public List<TAbbBanner> getHuigouBanner(){
		List<TAbbBanner> list = tAbbBannerMapper.getIndexBanner(2);
		return list;
	}

}
